//
//  NYUserModel.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2017/9/22.
//  Copyright © 2017年 niuwaketang. All rights reserved.
//

#import "NYUserModel.h"

@implementation NYUserModel
@synthesize nickname = _nickname;
@synthesize country_code = _country_code;
@synthesize gender = _gender;
+ (NSDictionary<NSString *,id> *)modelCustomPropertyMapper
{
        NYUserModel *model;
        return @{
                 @keypath(model,user_id) : @[@"uid"],
                 @keypath(model,mobile) : @[@"usermobile"],
                  @keypath(model,nickname) : @[@"nickname",@"nicename"],
                  @keypath(model,avatar) : @[@"avatar",@"img"],
                 };
}
- (NSString *)country_code
{
        if (!_country_code) {
                _country_code = @"86";
        }
        return _country_code;
}
- (NSString *)gender
{
        if (NULLString(_gender)) {
                switch (_sex.integerValue) {
                        case 1:
                                _gender = @"男";
                                break;
                        case 2:
                                _gender = @"女";
                                break;
                                
                        default:
                                _gender = @"保密";
                                break;
                }
        }
        return _gender;
}
- (void)setGender:(NSString *)gender
{
        _gender = gender;
        if ([gender isEqualToString:@"男"])
        {
                _sex = @"1";
        } else if ([gender isEqualToString:@"女"]) {
                _sex = @"2";
        } else {
                _sex = @"0";
        }
}

//===========================================================
// + (BOOL)automaticallyNotifiesObserversForKey:
//
//===========================================================
+ (BOOL)automaticallyNotifiesObserversForKey: (NSString *)theKey
{
        BOOL automatic;

        if ([theKey isEqualToString:@keypath(NYUserManager,user_id)]) {
                automatic = NO;
        } else if ([theKey isEqualToString:@keypath(NYUserManager,mobile)]) {
                automatic = NO;
        } else if ([theKey isEqualToString:@keypath(NYUserManager,nickname)]) {
                automatic = NO;
        } else if ([theKey isEqualToString:@keypath(NYUserManager,avatar)]) {
                automatic = NO;
        } else if ([theKey isEqualToString:@keypath(NYUserManager,role)]) {
                automatic = NO;
        } else if ([theKey isEqualToString:@keypath(NYUserManager,token)]) {
                automatic = NO;
        } else if ([theKey isEqualToString:@keypath(NYUserManager,refresh_token)]) {
                automatic = NO;
        } else if ([theKey isEqualToString:@keypath(NYUserManager,country_code)]) {
                automatic = NO;
        } else {
                automatic = [super automaticallyNotifiesObserversForKey:theKey];
        }

        return automatic;
}
//===========================================================
// - setUser_id:
//===========================================================
- (void)setUser_id:(NSString *)anUser_id
{
        if (_user_id != anUser_id) {
                [self willChangeValueForKey:@keypath(NYUserManager,user_id)];
                _user_id = [anUser_id copy];
                [self didChangeValueForKey:@keypath(NYUserManager,user_id)];
        }
}
//===========================================================
// - setPhone:
//===========================================================
- (void)setMobile:(NSString *)mobile
{
        if (_mobile != mobile) {
                [self willChangeValueForKey:@keypath(NYUserManager,mobile)];
                _mobile = [mobile copy];
                [self didChangeValueForKey:@keypath(NYUserManager,mobile)];
        }
}

//===========================================================
// - setNick_name:
//===========================================================
- (void)setNick_name:(NSString *)aNick_name
{
        if (_nickname != aNick_name) {
                [self willChangeValueForKey:@keypath(NYUserManager,nickname)];
                _nickname = [aNick_name copy];
                [self didChangeValueForKey:@keypath(NYUserManager,nickname)];
        }
}

//===========================================================
// - setAvatar:
//===========================================================
- (void)setAvatar:(NSString *)anAvatar
{
        if (_avatar != anAvatar) {
                [self willChangeValueForKey:@keypath(NYUserManager,avatar)];
                _avatar = [anAvatar copy];
                [self didChangeValueForKey:@keypath(NYUserManager,avatar)];
        }
}

//===========================================================
// - setRole:
//===========================================================
- (void)setRole:(NSString *)aRole
{
        if (_role != aRole) {
                [self willChangeValueForKey:@keypath(NYUserManager,role)];
                _role = [aRole copy];
                [self didChangeValueForKey:@keypath(NYUserManager,role)];
        }
}
//===========================================================
// - setToken:
//===========================================================
- (void)setToken:(NSString *)aToken
{
        if (_token != aToken) {
                [self willChangeValueForKey:@keypath(NYUserManager,token)];
                _token = [aToken copy];
                [self didChangeValueForKey:@keypath(NYUserManager,token)];
        }
}
//===========================================================
// - setRefresh_token:
//===========================================================
- (void)setRefresh_token:(NSString *)aRefresh_token
{
        if (_refresh_token != aRefresh_token) {
                [self willChangeValueForKey:@keypath(NYUserManager,refresh_token)];
                _refresh_token = [aRefresh_token copy];
                [self didChangeValueForKey:@keypath(NYUserManager,refresh_token)];
        }
}
//===========================================================
// - setCountry_code:
//===========================================================
- (void)setCountry_code:(NSString *)aCountry_code
{
        if (_country_code != aCountry_code) {
                [self willChangeValueForKey:@keypath(NYUserManager,country_code)];
                _country_code = [aCountry_code copy];
                [self didChangeValueForKey:@keypath(NYUserManager,country_code)];
        }
}


@end
